﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CacheManager.Core;

namespace PlatWL.Services.Tools
{
   public class CacheHelp
    {
        private static ICacheManager<object> manager = CacheFactory.Build("myCache",
               p => p.WithSystemRuntimeCacheHandle()
               .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromHours(1)));

        public static T Get<T>(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return default(T);
            }
            return manager.Get<T>(key);
        }

        public static object Get(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return null;
            }
            return manager.Get<object>(key);
        }

        public static string Put(string key, object value)
        {
            if (manager.Get(key) != null)
            {
                manager.Remove(key);
            }
            manager.Put(key, value);
            return key;
        }
    }
}

